window.onload = function() {
	var tension = new Tension();
	tension.length = 34.9;
	tension.gauge = 0.009;
	var display = new Display('tensionCalc', tension);

	var hiloStrings = 
	{'Martin M600': 
	 {'description': '',
	  'tension': [new Tension('ナイロン', '0.025', '35', 'A4'),
				  new Tension('ナイロン', '0.036', '35', 'D4'),
				  new Tension('ナイロン', '0.032', '35', 'F#4'),
				  new Tension('ナイロン', '0.021', '35', 'B4')]},
	 'FloloNylon1': 
	 {'description': '',
	  'tension': [new Tension('ナイロン', '0.028', '35', 'G4'),
				  new Tension('フロロ',   '0.0291', '35', 'C4'),
				  new Tension('フロロ',   '0.026', '35', 'E4'),
				  new Tension('ナイロン', '0.026', '35', 'A4')]},
	 'FloloNylon2': 
	 {'description': '',
	  'tension': [new Tension('ナイロン', '0.026', '35', 'G4'),
				  new Tension('フロロ',   '0.0291', '35', 'C4'),
				  new Tension('フロロ',   '0.026', '35', 'E4'),
				  new Tension('ナイロン', '0.024', '35', 'A4')]},
	 'Worth Medium': 
	 {'description': '',
	  'tension': [new Tension('フロロ', '0.0224', '35', 'G4'),
				  new Tension('フロロ', '0.0291', '35', 'C4'),
				  new Tension('フロロ', '0.0260', '35', 'E4'),
				  new Tension('フロロ', '0.0205', '35', 'A4')]},
	 'HiloStrings StandardSet': 
	 {'description': '',
	  'tension': [new Tension('ナイロン', '0.028', '35', 'G4'),
				  new Tension('ナイロン', '0.039', '35', 'C4'),
				  new Tension('ナイロン', '0.033', '35', 'E4'),
				  new Tension('ナイロン', '0.026', '35', 'A4')]}};
	new DisplayGroup('hiloStrings', hiloStrings);

	var guitarStrings =  
	{'savares': 
	 {'description': '',
	  'tension': [new Tension('フロロ', '0.034', '43.3', 'C4'),
				  new Tension('フロロ', '0.028', '43.3', 'E4'),
				  new Tension('ナイロン', '0.028', '43.3', 'A4')]}};
	new DisplayGroup('guitarStrings', guitarStrings);


};

function DisplayGroup(parentId, tensions) {
	var table = document.createElement('table');
	table.cellPadding = 5;
	table.border = 1;
	var tbody = document.createElement('tbody');
	for (var brand in tensions) {
		var tr = document.createElement('tr');
		var td = document.createElement('td');
		td.colSpan = tensions[brand]['tension'].length + 1;
		var style = document.createElement('h5');
		var title = document.createTextNode(brand);
		var description 
			= document.createTextNode(tensions[brand]['description']);
		style.appendChild(title);
		td.appendChild(style);
		td.appendChild(description);
		tr.appendChild(td);
		tbody.appendChild(tr);

		// ゲージの行
		tr = document.createElement('tr');
		td = document.createElement('td');
		td.innerHTML = 'ゲージ [inch]<br>[mm]';
		tr.appendChild(td);
		for (var row=0; row<tensions[brand]['tension'].length; row++) {
			td = document.createElement('td');
			var res = tensions[brand]['tension'][row];
			var inchGauge = Math.round(10000 * res.gauge) / 10000;
			var mmGauge = Math.round(1000 * 25.4 * res.gauge) / 1000;
			td.innerHTML = inchGauge + '<br>' + mmGauge;
			tr.appendChild(td);
		}
		tbody.appendChild(tr);
		// 長さ質量の行
		tr = document.createElement('tr');
		td = document.createElement('td');
		td.appendChild(document.createTextNode('長さ質量 [g/cm]'));
		tr.appendChild(td);
		for (var row=0; row<tensions[brand]['tension'].length; row++) {
			td = document.createElement('td');
			var res = tensions[brand]['tension'][row];
			var cell = document.
				createTextNode(Math.round(10000 * res.lengthMass) / 10000);
			td.appendChild(cell);
			tr.appendChild(td);
		}
		tbody.appendChild(tr);
		// トーンの行
		tr = document.createElement('tr');
		td = document.createElement('td');
		td.appendChild(document.createTextNode('トーン'));
		tr.appendChild(td);
		for (var row=0; row<tensions[brand]['tension'].length; row++) {
			td = document.createElement('td');
			var res = tensions[brand]['tension'][row];
			var cell = document.createTextNode(res.tone)
			td.appendChild(cell);
			tr.appendChild(td);
		}
		tbody.appendChild(tr);
		// テンションの行
		tr = document.createElement('tr');
		td = document.createElement('td');
		td.appendChild(document.createTextNode('テンション [kg]'));
		tr.appendChild(td);
		for (var row=0; row<tensions[brand]['tension'].length; row++) {
			td = document.createElement('td');
			var res = tensions[brand]['tension'][row];
			var cell = document.createTextNode(res.tension)
			td.appendChild(cell);
			tr.appendChild(td);
		}
		tbody.appendChild(tr);
	}
	table.appendChild(tbody);
	$(parentId).appendChild(table);
}
